package com.jinunn.user.controller;

import com.atguigu.yygh.model.user.Patient;
import com.jinunn.common.result.Result;
import com.jinunn.user.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author : JinDun
 * @date : 2021/5/19 22:25
 */

@Api(tags = "就诊人管理")
@RestController
@RequestMapping("/api/user/patient")
public class PatientController {

    @Autowired
    private PatientService patientService;

    @ApiOperation("根据当前登录用户，获取就诊人列表")
    @GetMapping("auth/findAll")
    public Result<List<Patient>> findAll(HttpServletRequest request){
        List<Patient> list = patientService.findAll(request);
        return Result.ok(list);
    }

    @ApiOperation("添加就诊人")
    @PostMapping("auth/save")
    public Result<Patient> savePatient(@RequestBody Patient patient,HttpServletRequest request){
        boolean result= patientService.savePatient(patient,request);
        if (result){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    @ApiOperation("根据id获取就诊人信息")
    @GetMapping("auth/detail/{id}")
    public Result<Patient> patientDetail(@PathVariable("id") Long id){
        Patient patient = patientService.patientDetail(id);
        return Result.ok(patient);
    }

    @ApiOperation("修改就诊人信息")
    @PostMapping("auth/update")
    public Result<Patient> updatePatient(@RequestBody Patient patient){
        boolean result = patientService.updatePatient(patient);
        if (result){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    @ApiOperation("删除就诊人信息")
    @DeleteMapping("auth/delete/{id}")
    public Result<Patient> deletePatient(@PathVariable("id") Long id){
       boolean result =  patientService.deletePatient(id);
       if (result){
           return Result.ok();
       }else {
           return Result.fail();
       }
    }

    @ApiOperation("根据就诊人id获取信息")
    @GetMapping("inner/get/{id}")
    public Patient getPatient(@PathVariable("id") Long id){
        return patientService.patientDetail(id);
    }

}
